/**
 * 
 */
package com.servicecloud.filter;

import java.util.UUID;

import javax.servlet.http.HttpServletResponse;

import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;

/**
 * 
 *
 * @author Gavin<br>
 *         后置过滤 2020年4月10日
 */
@Component
public class PostZuulFilter extends ZuulFilter {

	/* 
	 */
	@Override
	public boolean shouldFilter() {
		// TODO Auto-generated method stub
		return true;
	}

	/* 
	 */
	@Override
	public Object run() {
		RequestContext requestContext = RequestContext.getCurrentContext();// 获取上下文内容
		HttpServletResponse response = requestContext.getResponse();// 获取到request对象，然后可以对request里面的参数进行校验
		response.setHeader("X-Foo", UUID.randomUUID().toString());//返回信息
		return null;
	}

	/* 
	 */
	@Override
	public String filterType() {
		// TODO Auto-generated method stub
		return FilterConstants.POST_TYPE;
	}

	/* 
	 */
	@Override
	public int filterOrder() {
		// 后置过滤器一般放到SEND_RESPONSE_FILTER_ORDER过滤器之前
		return FilterConstants.SEND_RESPONSE_FILTER_ORDER - 1;
	}

}
